home *** CD-ROM | disk | FTP | other *** search
- /* Figure from Kaypro Column in Micro Cornucopia Magazine Issue #41
- * PAIR
- *
- * Checks whether quotes, )'s, ]'s, etc. are paired in text file
- *
- * Written for Small-C compiler vers. 2.03 (ASM)
- *
- * Date: 7/8/87
- */
-
- #include <stdioa.h>
- #include "iolib.asm"
- #include "call.asm"
-
- #define NOCCARGC
- #define HIGHBIT 127 /* high bit mask (= 01111111b) */
- #define WORDSTAR /* check WordStar print controls */
-
- int infile,
- lparen,
- rparen,
- lbrack,
- rbrack,
- lcurl,
- rcurl,
- quote,
- #ifdef WORDSTAR
- ctrls,
- ctrlb,
- #endif
- ok;
- char fname[15];
-
-
- main(argc,argv) int argc, argv[]; {
- int ch;
-
- fputs("PAIR vers. 2/20/87\n",stderr);
-
- if (argc >= 2)
- infile = fopen(argv[1],"r");
- else {
- #ifdef WORDSTAR
- fputs("Checks pairing of ), }, ], \", ^S, and ^B\n",stderr);
- #else
- fputs("Checks pairing of ), }, ], and \"\n",stderr);
- #endif
- fputs("Name of file to check: ? ",stderr);
- gets(fname);
- infile = fopen(fname,"r");
- }
-
- if (infile == NULL) {
- fputs("File not found.",stderr);
- exit();
- }
-
- lparen = rparen = lbrack = rbrack = 0;
- lcurl = rcurl = quote = ctrls = ctrlb = 0;
- ok = YES;
-
- fputs("\nReading file ...\n",stderr);
-
- while ((ch = getc(infile)) != EOF) {
- switch (ch & HIGHBIT) { /* strip high bit */
- case ')' : ++rparen; break;
- case '(' : ++lparen; break;
- case ']' : ++rbrack; break;
- case '[' : ++lbrack; break;
- case '}' : ++lcurl; break;
- case '{' : ++rcurl; break;
- case '\"' : ++quote; break;
- #ifdef WORDSTAR
- case '\023' : ++ctrls; break;
- case '\002' : ++ctrlb;
- #endif
- }
- }
-
- if (lparen != rparen) {
- fputs("Right and left parentheses unequal\n",stderr);
- ok = NO;
- }
-
- if (lbrack != rbrack) {
- fputs("Right and left brackets unequal\n",stderr);
- ok = NO;
- }
-
- if (lcurl != rcurl ) {
- fputs("Right and left curly braces unequal\n",stderr);
- ok = NO;
- }
-
- if ( quote % 2 != 0 ) {
- fputs("Quotation marks not balanced\n",stderr);
- ok = NO;
- }
-
- #ifdef WORDSTAR
-
- if ( ctrls % 2 != 0 ){
- fputs("Ctrl S underline controls not balanced\n",stderr);
- ok = NO;
- }
-
- if ( ctrlb % 2 != 0 ){
- fputs("Ctrl B boldface controls not balanced\n",stderr);
- ok = NO;
- }
-
- #endif
-
- if (ok)
- fputs("No errors found\n",stderr);
-
- fclose(infile);
- }